<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // var strs = `ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&tn=baidu&wd=%E5%AD%A6%E6%8C%96%E6%8E%98%E6%9C%BA%E5%88%B0%E5%BA%95%E5%93%AA%E5%AE%B6%E5%BC%BA&fenlei=256&rsv_pq=0x91f1bcb8000031f0&rsv_t=e569Oy35BGKkWyj3srJada%2B6YP2yx9%2BODfwC35RxX1i5agzwAr7qKdJ24A2Y&rqlang=en&rsv_enter=1&rsv_dl=tb&rsv_sug3=37&rsv_sug1=28&rsv_sug7=101&rsv_sug2=0&rsv_btype=i&prefixsug=%25E5%25AD%25A6%25E6%258C%2596%25E6%258E%2598%25E6%259C%25BA%25E5%2588%25B0%25E5%25BA%2595%25E5%2593%25AA%25E5%25AE%25B6%25E5%25BC%25BA&rsp=5&inputT=8599&rsv_sug4=10945`;
        // {ie:'utf-8',f:8,'rsv_bp':1,....}
        // 第一次需要按照 &
        // [ie=utf-8,f=8,rsv_bp=1,rsv_idx=1,....]

        // 遍历
        // ie=utf-8    用 = 切割  [ie,'utf-8']
        // f=8          用 = 切割  [f,8]
        //rsv_bp=1       用 = 切割  [rsv_bp,1]
        // rsv_idx=1    用 = 切割  [rsv_idx,1]

        // {数组的下标0作为键:数组下标1作为值}
        // var res = {};

        // var data = strs.split('&');
        // console.log(data)
        // for(var v of data){
        //     // console.log(v);
        //     var newarr = v.split('=');
        //     // console.log(newarr[0],newarr[1])
        //     res[newarr[0]] = newarr[1]
        // }

        // console.log(res);


        var obj = {
            name:'张三',
            age:18
        }

        // name=张三&age=18   最终结果是字符串 

     
        // 键=值&
        // 键=值&
        // `${键}=${值}&`
        // 准备用1个空字符串  

        // 拿到键值
        // 组装成 `${键}=${值}&`
        // 拼接到空字符串 后面 
        var str = '' ;// 准备一个空字符串
        for(var k in obj){
              
            str+=`${k}=${obj[k]}&`
        }

        console.log(str); // 键=值&键=值&键=值&键=值&
        //                   0 12 34 567 891011121314
        str = str.slice(0,-1); // 等同于slice(0,字符串的长度-1)
        // [0,字符串的长度-2]

        console.log(str)

        var datas = 'https://www.baidu.com/s?'+str;
        console.log(datas);
    </script>
</body>
</html>